package com.project.ServiceImp;

import com.alibaba.dubbo.config.annotation.Service;
import com.project.mapper.ChargeDispensingDao;
import gz.ChargeDispensingService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ChargeDispensingService.class)
@Component
@Transactional
public class ChargeDispensingServiceImp implements ChargeDispensingService {

    @Resource
    private ChargeDispensingDao cd;


    /**
     * 查询出所有的未就诊的患者
     * @param name
     * @param status
     * @return
     */
    @Override
    public List<Map<String, Object>> AllChargeDis(String name, Integer status) {
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("status",status);
        return cd.AllChargeDis(map);
    }


    /**
     * 点击收费按钮获取相关的数据
     * @param id
     * @return
     */
    @Override
    public List<Map<String, Object>> Person_Charge(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return cd.Person_Charge(map);
    }


    /**
     * 如收费成功则修改患者状态
     * @param id
     * @return
     */
    @Override
    public int update_status(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return cd.update_status(map);
    }


    /**
     * 如退款成功则修改患者状态为已退款
     * @param id
     * @return
     */
    @Override
    public int update_tuikuan(Integer id) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        return cd.Update_Tuikuan(map);
    }


    /**
     * 如现金支付成功则新增记录到表中
     * @param h
     * @param money
     * @param res
     * @param p
     * @return
     */
    @Override
    public int money_record_all(Integer h, Integer res, Integer p, Double money,String code) {
        Map<String,Object> map = new HashMap<>();
        map.put("money",money);
        map.put("patient_id",p);
        map.put("registration_id",res);
        map.put("history_id",h);
        map.put("order_code",code);
        return cd.money_record_all(map);
    }

    /**
     * 如微信支付成功则新增记录到表中
     * @param id
     * @param money
     * @return
     */
    @Override
    public int weixin_record(Integer id, Double money) {
        Map<String,Object> map = new HashMap<>();
        map.put("pkg_id",id);
        map.put("money",money);
        return cd.weixin_record(map);
    }


    /**
     * 如退款成功则新增记录到表中
     * @param id
     * @param money
     * @param pkg
     * @return
     */
    @Override
    public int insert_tuikuan(Integer id, Double money, Integer pkg) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("money",money);
        map.put("pkg",pkg);
        return cd.insert_tuikuan(map);
    }


    /**
     * 记录添加成功之后查询出记录的id
     * @param o
     * @return
     */
    @Override
    public int select_pkgId(String o) {
        Map<String,Object> map = new HashMap<>();
        map.put("order_code",o);
        return cd.select_pkgId(map);
    }

    /**
     * 如使用现金付款则添加信息到收费记录表中
     * @param d
     * @param money
     * @return
     */
    @Override
    public int money_record(Integer d, Double money) {
        Map<String,Object> map = new HashMap<>();
        map.put("pkg_id",d);
        map.put("money",money);
        return cd.money_record(map);
    }

    /**
     * 如微信支付成功则添加记录到收费总表中
     * @param h
     * @param res
     * @param p
     * @param money
     * @param code
     * @return
     */
    @Override
    public int weixin_record_all(Integer h, Integer res, Integer p, Double money, String code) {
        Map<String,Object> map = new HashMap<>();
        map.put("money",money);
        map.put("patient_id",p);
        map.put("registration_id",res);
        map.put("history_id",h);
        map.put("order_code",code);
        return cd.weixin_record_all(map);
    }


    /**
     * 发药成功后修改患者的状态为完成交易
     * @param a
     * @return
     */
    @Override
    public int update_ok(Integer a) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",a);
        return cd.update_ok(map);
    }
}
